<?php
class ControllerWhislist { 

    function getFunction($op){
        
        switch ($op) {
            case "new":
                $this->newWhislist();
                break;
            
            case "list":
                $this->listWhislist();
                break;
            
            case "save":
                $this->saveWhislist();
                break;

            case "edit":
                $this->editWhislist();
                break;
            
            case "update":
                $this->updateWhislist();
                break;
            
            case "del":
                $this->deleteWhislist();
                break;
            
            case "combo":
                return $this->comboWhislist();
                break;
            
            default:
                echo "ERROR NO HAY CONTROLADOR PARA ESA OPCION";
                break;
        }
    }
    

    function newWhislist(){
        include_once "vista/vista.whislist.php";
        form_whislist();
    }    
    

    function saveWhislist(){
        include_once "modelo/modelo.whislist.php";
        
        $w = new whislist();
        $w->set_wl_id($_REQUEST["wl_id"]); 
        $w->set_wl_ph_id($_REQUEST["wl_ph_id"]); 
        $w->set_wl_p_id($_REQUEST["wl_p_id"]); 
        $w->set_wl_u_id($_REQUEST["wl_u_id"]); 
        $w->set_wl_date($_REQUEST["wl_date"]); 
        $w->set_wl_status($_REQUEST["wl_status"]); 

        
        if($w->Save()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_save_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_save_error']." </div>";
        }
        $this->listWhislist($msj);
        
    }    
    
    function editWhislist(){
        include_once 'modelo/modelo.whislist.php';
        include_once 'vista/vista.whislist.php';
        
        $w = new whislist();
        $w->setwl_id($_REQUEST["wl_id"]); 
        
        $w->getData();
        
        form_whislist($w);
        
    }    
    
    function deleteWhislist(){
        include_once 'modelo/modelo.whislist.php';
        
        $w = new whislist();
        $w->setwl_id($_REQUEST["wl_id"]); 
        
        if($w->Delete()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_delete_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_delete_error']." </div>";
        }
        $this->listWhislist($msj);
    }

    
    function updateWhislist(){
        include_once 'modelo/modelo.whislist.php';
        
        $w = new whislist();
        $w->set_wl_id($_REQUEST["wl_id"]); 
        $w->set_wl_ph_id($_REQUEST["wl_ph_id"]); 
        $w->set_wl_p_id($_REQUEST["wl_p_id"]); 
        $w->set_wl_u_id($_REQUEST["wl_u_id"]); 
        $w->set_wl_date($_REQUEST["wl_date"]); 
        $w->set_wl_status($_REQUEST["wl_status"]); 

        if($w->Update()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_update_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_update_error']." </div>";
        }
        $this->listWhislist($msj);
    }

    
    function listWhislist($msj=false){
        include_once 'modelo/modelo.whislist.php';
        include_once 'vista/vista.whislist.php';
        
        $w = new whislist();

        $w->setwl_id($_REQUEST["wl_id"]); 
        $w->getData();
        
        $dataTotal = $w->GetList(" count(*) ", false,  true);
        $dataTotal = $dataTotal[0][0]; 
        $data = $w->GetList(" * ", false);
        if(is_null($data)){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_empty_error']." </div>";
        }
        list_whislist($data, $msj, $dataTotal);

    }

}